// import com.alibaba.druid.sql.ast.SQLCommentHint;
// import com.alibaba.druid.sql.ast.SQLExpr;
// import com.alibaba.druid.sql.ast.SQLName;
// import com.alibaba.druid.sql.ast.SQLStatementImpl;
// import com.alibaba.druid.sql.ast.expr.SQLPropertyExpr;
// import com.alibaba.druid.sql.visitor.SQLASTVisitor;

// import java.util.List;

#include "SQLShowIndexesStatement.h"
#include "../../visitor/SQLASTVisitor.h"
#include "../../../utils/instanceof.h"
#include "SQLExprTableSource.h"

SQLShowIndexesStatement::SQLShowIndexesStatement()
{
  hints = std::make_shared<std::list<SQLCommentHint_ptr>>();
}

SQLExprTableSource_ptr SQLShowIndexesStatement::getTable()
{
  return table;
}

void SQLShowIndexesStatement::setTable(SQLName_ptr table)
{
  setTable(SQLExprTableSource_ptr(new SQLExprTableSource(table)));
}

void SQLShowIndexesStatement::setTable(SQLExprTableSource_ptr table)
{
  this->table = table;
}

SQLName_ptr SQLShowIndexesStatement::getDatabase()
{
  SQLExpr_ptr expr = table->getExpr();
  if (instanceof <SQLExpr, SQLPropertyExpr>(expr))
  {
    return std::dynamic_pointer_cast<SQLName>((std::dynamic_pointer_cast<SQLPropertyExpr>(expr))->getOwner());
  }
  return nullptr;
}

SQLExpr_ptr SQLShowIndexesStatement::getWhere()
{
  return where;
}

void SQLShowIndexesStatement::setWhere(SQLExpr_ptr where)
{
  this->where = where;
}

string_ptr SQLShowIndexesStatement::getType()
{
  return type;
}

void SQLShowIndexesStatement::setType(string_ptr type)
{
  this->type = type;
}

void SQLShowIndexesStatement::setDatabase(string_ptr database)
{
  table->setSchema(database);
}

void SQLShowIndexesStatement::accept0(SQLASTVisitor_ptr visitor)
{
  if (visitor->visit(SharedObject(SQLShowIndexesStatement)))
  {
    acceptChild(visitor, table);
    acceptChild(visitor, where);
  }
  visitor->endVisit(SharedObject(SQLShowIndexesStatement));
}

SQLCommentHint_list_ptr SQLShowIndexesStatement::getHints()
{
  return hints;
}

void SQLShowIndexesStatement::setHints(SQLCommentHint_list_ptr hints)
{
  this->hints = hints;
}
